// pages/home/home.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    advert: [], //广告列表
    btmType: 1, //底部tag选项值
    btmNavs: [{
      id: 1,
      name: '产业工人'
    },
    //  {
    //   id: 2,
    //   name: '建材家居'
    // },
    //  {
    //   id: 3,
    //   name: '辅材品牌'
    // }
  ],
    offerDetail: '', //精算链接
    cShow: 'show',
    dShow: 'hide'
  },

  hideShow() {
    this.calculatePop[`${this.data.cShow}`]()
    this.downloadPop[`${this.data.dShow}`]()
  },

  navDetail(e) {
    let goodsId = e.currentTarget.dataset.id
    wx.$nav('/pages/workerDetail/workerDetail', {
      goodsId: goodsId
    })
  },

  navShop(e) {
    let shopId = e.currentTarget.dataset.id
    wx.$nav('/pages/shop/shop', {
      shopId: shopId
    })
  },

  navShopDetail(e) {
    let goodsId = e.currentTarget.dataset.id
    wx.$nav('/pages/workerDetail/workerDetail', {
      goodsId: goodsId
    })
  },

  navGetCoupon() {
    wx.$isLogin(() => {
      wx.$nav('/pages/getCoupon/getCoupon', {
        // list: JSON.stringify(this.data.coupons),
        shopId: 0
      })
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (wx.getStorageSync('dot') == 1) {
      wx.showTabBarRedDot({
        index: 2,
      })
    }
  },

  changeType: function (e) {
    let that = this;
    let type = e.currentTarget.dataset.type
    that.setData({
      btmType: type
    })
  },

  topNav(e) {
    let id = e.currentTarget.dataset.id
    let type = e.currentTarget.dataset.type
    if (type == 1) {
      wx.$nav('/pages/workerDetail/workerDetail', {
        goodsId: id
      })
    } else if (type == 2) {
      wx.$nav('/pages/shop/shop', {
        shopId: id
      })
    } else if (type == 6) {
      wx.$nav('/pages/service/service')
    } else if (type == 7) {
      wx.$nav('/pages/trimFlow/trimFlow')
    } else if (type == 8) {
      wx.$nav('/pages/enter/enter', {
        type: 1
      })
    } else if (type == 9) {
      wx.$nav('/pages/enter/enter', {
        type: 2
      })
    } else if (type == 10) {
      wx.$nav('/pages/enter/enter', {
        type: 3
      })
    }
  },

  cost: function () {
    wx.$nav('/pages/cost/cost')
  },

  service() {
    wx.$nav('/pages/service/service')
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.calculatePop = this.selectComponent("#calculatePop");
    this.downloadPop = this.selectComponent("#downloadPop");
    if (wx.getStorageSync('calcShow') == 1) {
      this.setData({
        cShow: 'hide'
      })
    }
    this.hideShow()
  },

  offerAdd(res) {
    this.setData({
      offerDetail: res.detail,
      cShow: 'hide',
      // dShow: 'show'
    })
    wx.setStorageSync('calcShow', 1)
    this.hideShow()
    wx.showTabBarRedDot({
      index: 2,
    })
    wx.setStorageSync('dot', 1)
  },

  popHide() {
    this.setData({
      dShow: 'hide'
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this
    wx.$https('index.list').then(res => {
      this.setData({
        ...res
      })
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    this.setData({
      cShow: 'hide'
    })
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})